﻿using Entities;
using hpcpdi.DataAccess.Base;
using hpcpdi.DataAccess.Interface;
using hpcpdi.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;


namespace Repositories.Impl
{
    public class UserRepository:IUserRepository
    {
        private readonly Context _context;
        private readonly ILogger _logger;
        
        public UserRepository(Context context, ILoggerFactory logFactory)
        {
            _context = context;
            _logger = logFactory.CreateLogger<UserRepository>();
        }
        //查找数据
        public async Task<User> GetUser(string username, string password)
        {
            //string sql = "select id,username,pwd,createtime,disable from user";
            try
            {
                Task<User> user = _context.User.Where(s => s.username == username && s.pwd == password).FirstOrDefaultAsync();
                return await user;
            }
            catch (Exception ex)
            {
                _logger.LogError( ex.Message+ "\r\n StackTrace" + ex.StackTrace);
                return null;
            }
        }
    }
}
